package 初级算法;

public class 加一 {
    public static void main(String[] args) {
        int[] is = new int[]{3,4,6,9};
        for (int i : plusOne(is)) {
            System.out.println(i);
        }
    }

    public static int[] plusOne(int[] digits) {
        for (int i = digits.length - 1; i >= 0; i--) {
            if(digits[i]==9){
                digits[i] = 0;
            }else{
                digits[i] = digits[i] +1;
                return digits;
            }
        }
        int[] n = new int[digits.length+1];
        n[0]=1;
        return n;
    }
}
